package me.tuyou.jms.java;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

public class ActiveMqConsumerApp {
    public static void main(String[] args) throws JMSException {
        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
        Connection connection = connectionFactory.createConnection();
        connection.start();

        Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
        Queue test = session.createQueue("test");
        MessageConsumer consumer = session.createConsumer(test);

        while (true) {
            TextMessage receive = (TextMessage) consumer.receive();
            session.commit();
            System.out.println("收到消息：" + receive.getText());
        }
    }
}
